package view;

import com.example.pruebapfi.R;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

public class Header extends LinearLayout {
  private TextView title;
  public Header(final Context context, AttributeSet attrs) {
    super(context, attrs);

    setOrientation(LinearLayout.HORIZONTAL);
    setGravity(Gravity.CENTER_VERTICAL);

    LayoutInflater inflater = (LayoutInflater) context
        .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(R.layout.header, this, true);
    this.title=(TextView) findViewById(R.id.textTitleHeader);
    
    

  }

  public Header(Context context) {
    this(context, null);
  }

  public void setTitle(String title) {
    this.title.setText(title);
  }
  public void setActivity(final Activity activity,final int help_layout) {
	    Button back=(Button) findViewById(R.id.back);
		Button home=(Button) findViewById(R.id.homeBack);
		Button button_support=(Button) findViewById(R.id.ButtonHeaderSupport);
		button_support.setOnClickListener(new OnClickListener() {
       	 public void onClick(View v) {
       		 	final Dialog mDialog = new Dialog(v.getContext());
       		 	mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
       		 	mDialog.setContentView(help_layout);
       		    Drawable d = new ColorDrawable(R.color.gray_background);
       		    d.setAlpha(180);
       		    mDialog.getWindow().setBackgroundDrawable(d);
       		    mDialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,WindowManager.LayoutParams.MATCH_PARENT);
       		    mDialog.show();
       		    
       		    LinearLayout layout = (LinearLayout) mDialog.findViewById(R.id.overlayLayout);

       			layout.setOnClickListener(new OnClickListener() {

       				@Override

       				public void onClick(View arg0) {

       					mDialog.dismiss();

       				}

       			});
       		    
       	 }
        });
		back.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				activity.finish();
			}
		});
		home.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Intent intent= new Intent(activity.getApplicationContext(),MainActivity.class);
				activity.startActivity(intent);
				activity.finish();
			}
		});
	  }

} 